package com.sphd.Restaurant.presenter;

import android.widget.Toast;

import com.android.volley.VolleyError;
import com.sphd.Restaurant.interfFace.VolleyCallBack;
import com.sphd.Restaurant.utils.VolleyErrorHelper;
import com.sphd.Restaurant.views.RegisterView;


import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by Hu on 2016/10/20.
 */

public class RegisterP extends BasePresenter implements VolleyCallBack<JSONObject> {

    RegisterView registerView;
    public RegisterP(RegisterView registerView) {
        this.registerView = registerView;
    }

    @Override
    public void addData(String url) {
        registerView.showdialog();
        sendJsonObjectUrl(url,this);
    }

    @Override
    public void onResponse(JSONObject object) {
        try {
            int res=object.getInt("res");
           registerView.sendRes(res);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        registerView.dissmissdialog();
    }



    @Override
    public void onErrorResponse(VolleyError error) {
        registerView.dissmissdialog();
        Toast.makeText(context, VolleyErrorHelper.getMessage(error),Toast.LENGTH_SHORT).show();
    }
}
